<template>
	<view class="help-container">
		<!-- 页面标题 -->
		<view class="header">
			<text class="title">常见问题</text>
		</view>

		<!-- FAQ列表 -->
		<scroll-view
			class="faq-list"
			scroll-y="true"
			@scrolltolower="loadMore"
		>
			<view
				class="faq-item"
				v-for="(item, index) in faqList"
				:key="item.id"
			>
				<!-- 问题行 -->
				<view class="question-row" @click="toggleAnswer(index)">
					<view class="question-content">
						<text class="question-number">{{ index + 1 }}、</text>
						<text class="question-text">{{ item.questionTitle }}</text>
					</view>
					<view class="arrow-icon">
						<u-icon
							:name="item.isExpanded ? 'arrow-up' : 'arrow-down'"
							size="16"
							color="#999"
						></u-icon>
					</view>
				</view>

				<!-- 答案内容 -->
				<view
					class="answer-content"
					:class="{ 'expanded': item.isExpanded }"
				>
					<text class="answer-text">{{ item.answer }}</text>
				</view>
			</view>

			<!-- 紫色虚线分隔符 -->
			<view class="scroll-divider">
				<view class="dashed-line"></view>
			</view>

			<!-- 底部提示 -->
			<view class="bottom-tip" v-if="noMore">已经到底了</view>
		</scroll-view>
	</view>
</template>
<script>
	import { get } from "@/utils/request"; 
	import { jwtDecode } from 'jwt-decode';
	
export default {
	data() {
		return {
			faqList: [],
			pageNum: 1,
			pageSize: 10,
			total: 0,
			noMore: false
		}
	},
	onLoad() {
		this.getFaqList();
		this.getTest();
	},
	methods: {
		// 获取 FAQ 列表
		getFaqList() {
		  get("/transaction/yzmquestions/list", {
		    pageNum: this.pageNum,
		    pageSize: this.pageSize
		  }).then((res) => {
		    if (res.code === 200 && Array.isArray(res.rows)) {
		      this.faqList = res.rows.map(item => ({
		        ...item,
		        isExpanded: false // 前端额外加的字段
		      }));
		      console.log(this.faqList);
		    }
		  }).catch((err) => {
		    console.error("获取FAQ失败", err);
		  });
		},
		
		getTest() {
		  // 从本地存储获取 Token
		  const token1 = uni.getStorageSync('userId');
		  const token2 = uni.getStorageSync('userName');
		 console.log("userId --- "+token1)
		 console.log("userName --- "+token2)
		 
		},

		// 切换答案展开/收起
		toggleAnswer(index) {
			this.faqList.forEach((item, i) => {
				if (i !== index) {
					item.isExpanded = false;
				}
			});
			this.faqList[index].isExpanded = !this.faqList[index].isExpanded;
		},

		// 加载更多
		loadMore() {
			if (this.noMore) return;
			this.pageNum++;
			this.getFaqList();
			
		}
	}
}
</script>
<style lang="scss" scoped>
.help-container {
	background-color: #ffffff;
	min-height: 100vh;
	position: relative;
}

// 页面标题
.header {
	background-color: #ffffff;
	padding: 30rpx 40rpx;
	position: relative;
	border-bottom: 2rpx solid #e5e5e5;

	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}
}

// FAQ列表
.faq-list {
	height: calc(100vh - 120rpx);
	background-color: #ffffff;
	position: relative;
}

// FAQ项目
.faq-item {
	background-color: #ffffff;
	border-bottom: 1rpx solid #e5e5e5;

	&:last-child {
		border-bottom: none;
	}
}

// 问题行
.question-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx 40rpx;
	cursor: pointer;
	transition: background-color 0.3s ease;

	&:active {
		background-color: #f2f2f2;
	}

	.question-content {
		flex: 1;
		display: flex;
		align-items: flex-start;

		.question-number {
			font-size: 28rpx;
			color: #333333;
			font-weight: 500;
			margin-right: 10rpx;
		}

		.question-text {
			font-size: 28rpx;
			color: #333333;
			line-height: 1.5;
			flex: 1;
		}
	}

	.arrow-icon {
		margin-left: 20rpx;
		transition: transform 0.3s ease;
	}
}

// 答案内容
.answer-content {
	max-height: 0;
	overflow: hidden;
	transition: max-height 0.3s ease, padding 0.3s ease;
	background-color: #f9f9f9;

	&.expanded {
		max-height: 500rpx;
		padding: 20rpx 40rpx 30rpx 80rpx;
	}

	.answer-text {
		font-size: 26rpx;
		color: #666666;
		line-height: 1.6;
	}
}

// 分隔符（实线浅灰）
.scroll-divider {
	position: relative;
	height: 40rpx;
	display: flex;
	align-items: center;
	justify-content: center;

	.dashed-line {
		width: 100%;
		height: 2rpx;
		background-color: #e5e5e5;
	}
}

// 底部提示
.bottom-tip {
	background-color: #ffffff;
	text-align: center;
	color: #999999;
	font-size: 24rpx;
	padding: 30rpx 0;
	position: relative;

	&::after {
		content: '';
		position: absolute;
		bottom: 10rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 60rpx;
		height: 8rpx;
		background-color: #dcdcdc;
		border-radius: 4rpx;
	}
}

// 滚动条样式（自定义）
.faq-list::-webkit-scrollbar {
	width: 8rpx;
}

.faq-list::-webkit-scrollbar-track {
	background: #f1f1f1;
	border-radius: 4rpx;
}

.faq-list::-webkit-scrollbar-thumb {
	background: #c1c1c1;
	border-radius: 4rpx;
}

.faq-list::-webkit-scrollbar-thumb:hover {
	background: #a8a8a8;
}
</style>
